﻿using System;
using System.Collections.Generic;
using System.Text;
using jade.core;
using System.Drawing;

namespace MarketSimulator.Utils.Attributes
{
    /// <summary>
    /// Base class for all Actors
    /// </summary>
    public abstract class GeneralAttributes
    {
        private static readonly object ActorsWriteLock = new object();

        /// <summary>
        /// Jade Agent
        /// </summary>
        public Agent JadeAgent { get; set; }
        
        /// <summary>
        /// Action for Writing a Message
        /// </summary>
        public Action<string> WriteMessageAction { get; private set; }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="writeMessageAction"></param>
        public GeneralAttributes(Action<string> writeMessageAction)
        {
            WriteMessageAction = writeMessageAction;
        }

        /// <summary>
        /// Write Message
        /// </summary>
        /// <param name="format"></param>
        /// <param name="parameters"></param>
        public void WriteMessage(string format, params object[] parameters)
        {
            lock (ActorsWriteLock)
            {
                string message = string.Format("[ {0} ] : {1} ", JadeAgent.getLocalName(), string.Format(format, parameters));
                WriteMessageAction(message);
            }
        }

        public abstract void RegisterAgent();
    }
}
